package zhou.cutfruit.util;

import java.util.HashMap;

import zhou.cutfruit.R;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
/**
 * 单例模式初始化音乐
 * @author 周雨浓
 *
 */
public class PreparedSoundSingle {

	private static PreparedSoundSingle instance = null;
	private static SoundPool soundPool;

	private static HashMap<Integer, Integer> soundMap = new HashMap<Integer, Integer>();

	private PreparedSoundSingle() {

	}

	public static void StartInstance(Context context) {

		soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 5);
		soundMap.put(1, soundPool.load(context, R.raw.slice_kiwifriut, 2));
		soundMap.put(2, soundPool.load(context, R.raw.wield_normal_middle, 2));
		soundMap.put(3, soundPool.load(context, R.raw.wield_reverse_high, 1));
		if (instance == null) {

			instance = new PreparedSoundSingle();
		}
	}

	public static PreparedSoundSingle getInstance() {
		return instance;
	}

	public HashMap<Integer, Integer> getSoundMap() {
		return soundMap;
	}

	private boolean playSound(int which) {
		try {
			soundPool.play(soundMap.get(which), 1, 1, 0, 0, 1);
		} catch (Exception e) {

		}

		return true;
	}

	public boolean playCutSound() {
		return playSound(3);
	}
	
	public boolean playCuttingFruitSound() {
		return playSound(1);
	}

	public boolean playWaterMelonSound() {
		return playSound(2);
	}

}
